package com.xiangban.yanglaodajie_platform.controller;

import com.alibaba.fastjson.JSON;
import com.xiangban.yanglaodajie_platform.aop.Permission;
import com.xiangban.yanglaodajie_platform.entity.AccumulatePoints;
import com.xiangban.yanglaodajie_platform.entity.Orders;
import com.xiangban.yanglaodajie_platform.entity.res.ApiResult;
import com.xiangban.yanglaodajie_platform.service.AccumulatePointsService;
import com.xiangban.yanglaodajie_platform.utils.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


/**
 * @Author Mr. MaYaYun
 * @Data 2021/3/30 10:06
 */
@Slf4j
@RestController
@RequestMapping("/api/pri/AccumulatePoints")
@Api(tags = "积分管理")
public class AccumulatePointsController {

    @Autowired
    private AccumulatePointsService accumulatePointsService;



//    @PostMapping("/addAccumulatePoints")
//    @ApiOperation("充值积分")
//    @Permission
//    public JsonData addAccumulatePoints(@RequestBody Map<String,Integer> map){
//        int i = accumulatePointsService.addAP(map);
//        return i== 1 ? JsonData.buildSuccess("充值成功") : JsonData.buildError("操作失败");
//    }
    @Permission
    @PostMapping("/topUpIntegral")
    @ApiOperation("充值积分")
    public ApiResult<Object> topUpIntegral(@RequestBody Map<String,Object> parameter){
        log.info("接收参数++++++ +-"+JSON.toJSONString(parameter));
        Map<String,String> res = accumulatePointsService.topUpIntegral(parameter);
        log.info("返回发起微信支付参数++++++"+JSON.toJSONString(res));
        return ApiResult.newSuccess(res);

    }

    @Permission
    @PostMapping("/getAddAccumulatePointsList")
    @ApiOperation("获取积分记录")
    public JsonData getAddAccumulatePointsList(@RequestBody AccumulatePoints accumulatePoints){
       return JsonData.buildSuccess(accumulatePointsService.getList(accumulatePoints),"获取成功");
    }

}
